package org.dromara.system.mq;

import org.dromara.system.domain.mq.OrderTrackParam;
import org.dromara.system.mq.config.OrderQueueConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrderTrackSender {
    private static final Logger log = LoggerFactory.getLogger(OrderTrackSender.class);

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void sendTrackMessage(OrderTrackParam param, long delayTime) {
        try {
            amqpTemplate.convertAndSend(OrderQueueConfig.DELAYED_EXCHANGE_NAME, OrderQueueConfig.DELAYED_TRACK_KEY, param, message -> {
                message.getMessageProperties().setDelayLong(delayTime);
                return message;
            });
        } catch (AmqpException e) {
            log.error("发起【推送订单物流】 异常{},{}", getClass(), e.getMessage());
        }
    }

}
